<?php
    header("content-type:textml;charset=utf-8");
    // $name = $_GET['username'];
    // $psw = $_GET['password'];
    $link = mysql_connect('localhost', 'root', 'root') or die('数据链接失败');
    mysql_select_db('fl', $link);
    $keyword = $_POST['keyword'];
    $id = $_POST['id'];
    $sql = "select * from `goods`";
    if($id) $sql .= "where id=$id";
    if($keyword) $sql .= "where `good_name` LIKE '%$keyword%'";
    $res = mysql_query($sql);
     // 匹配就是$row就是一个resource
     // 匹配不上$row返回就是false boolean
    $arr = [];
    if($res){
        while($row = mysql_fetch_assoc($res)){
            array_push($arr,$row);
        }
    }
    // echo json_encode($arr);
    // 总数据数
    $length=count($arr);
    // 总页码
    $yema=1;
    if(ceil($length)/9){
        $yema=ceil($length/9);
    }
    $arr1=['length'=>'0','data'=>'0','yema'=>$yema];
    $arr2=[];
    if($_POST['index']){
        $index=$_POST['index'];
    }else{
        $index=0;
    }
    
    // echo $index;  页码
    for($i=9*$index;$i<($index+1)*9 && $i<=$length-1;$i++){
        array_push($arr2,$arr[$i]);
    }
    $arr1['length']=$length;
    $arr1['data']=$arr2;
    echo json_encode($arr1);
?>

